<?php
declare(strict_types=1);
 

namespace App\Fastapp\Mapper;

use App\Fastapp\Model\AccountFeedback;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 反馈列表Mapper类
 */
class FastappAccountFeedbackMapper extends AbstractMapper
{
    /**
     * @var AccountFeedback
     */
    public $model;

    public function assignModel()
    {
        $this->model = AccountFeedback::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {

        // 用户id
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 1建议2投诉
        if (isset($params['type']) && filled($params['type'])) {
            $query->where('type', '=', $params['type']);
        }

        // 处理0否1是
        if (isset($params['status']) && filled($params['status'])) {
            $query->where('status', '=', $params['status']);
        }

        return $query->orderByDesc('id');
    }
}